package com.Auth;


import com.Mail.MailServer;

import java.util.Scanner;

public class AuthCodeSender {
    final private static String title = "学习通like的验证码标题";
    // %06d 是 补0，成6位数字
    final private static String content = "您的验证码为%06d，请在5分钟内输入，否则将会失效";

    public static void test(String email){
        // 测试验证码
        AuthCodeSender.sendAuthCodeMail(email);
        Scanner scanner = new Scanner(System.in);
        int code = scanner.nextInt();
        boolean i = AuthCodeSender.vertifyAuthCode("lsjlkz@163.com", code);

    }

    public static void sendAuthCodeMail(String eMail){
        int authCode = AuthCode.buildOneCodeAndReturn(eMail);
        // 发送验证码
        MailServer.prepareAndSend(eMail, title, String.format(content, authCode));
    }

    public static boolean vertifyAuthCode(String eMail, int code){
        // 验证验证码
        return AuthCode.isCorrect(eMail, code);
    }
}
